<template>
  <div class="cinema-schedule" v-if="cinema" :class="{ 'fix-header-title': isFixHeader }">
    <div class="header-left" @click="onClickLeft"><van-icon name="arrow-left" /></div>
    <div class="header-title" :class="{ 'fix-header-title': isFixHeader, 'set-header-top': isShowCinemaServices }">{{
      cinema.name }}</div>
    <div class="cinema-info">
      <van-row class="tags" align="center">
        <van-col gutter="1" span="3" class="tag" v-for="(service, index) in cinema.services" :key="index">
          <van-tag plain type="primary">{{ service.name }}</van-tag>
        </van-col>
        <van-icon name="arrow" size="14" color="var(--van-tag-primary-color)" v-if="cinema.services"
          style="margin-left: 10px;" />
      </van-row>
      <van-row class="info" align="center">
        <van-col class="location"><van-icon name="location-o" size="25" /></van-col>
        <van-col class="address" span="21">{{ cinema.address }}</van-col>
        <van-col class="telephone" span="3"><van-icon name="phone-o" size="24" /></van-col>
      </van-row>
      <FilmList :films="films" :cinemaId="cinema.cinemaId" />
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted, onUnmounted } from 'vue'
import { getCinemaInfo, getCinemaFilmsArrangement } from '@/api/index.js'
import { useRouter } from 'vue-router'
const router = useRouter()
import { useStore } from '@/stores/index.js'
import FilmList from '@/components/FilmList.vue'
const store = useStore()
const props = defineProps({
  id: {
    type: String,
    required: true,
  },
})
const cinema = ref(null)
const films = ref([])
const isFixHeader = ref(false)
const isShowCinemaServices = ref(false)
onMounted(async () => {
  //加载电影院详情信息
  const cinemaInfo = await getCinemaInfo(props.id)
  cinema.value = cinemaInfo.data.cinema
  // console.log("cinema.value ", cinema.value);
  // 加载电影院排片信息
  const filmsArrangement = await getCinemaFilmsArrangement(props.id)
  films.value = filmsArrangement.data.films
  // console.log('films.value ', films.value)
  // 添加滚动事件监听
  window.addEventListener('scroll', handleScroll)
})
onUnmounted(() => {
  // 移除滚动事件监听
  window.removeEventListener('scroll', handleScroll)
})
const onClickLeft = () => {
  store.setPageNum(1)
  router.push({ path: '/cinemas' })
};
const handleScroll = () => {
  if (window.scrollY >= 44) {
    isFixHeader.value = true
  } else {
    isFixHeader.value = false
  }
};
</script>
<style scoped>
.cinema-schedule {
  overflow: hidden;
  padding-top: 44px;
  background: #fff;
  min-height: 100vh;
  width: 100%;

}

.cinema-schedule.fix-header-title {
  padding-top: 0;

}


.cinema-schedule::-webkit-scrollbar {
  display: none;

}

.cinema-schedule {
  scrollbar-width: none;
  /* Firefox */
}

.cinema-schedule .set-header-top {
  position: fixed;
  top: 44px;
  z-index: 300;
}



.cinema-schedule .header-left {
  position: fixed;
  top: 0;
  height: 44px;
  line-height: 44px;
  padding-left: 15px;
  z-index: 301;
}

.cinema-schedule .header-title {
  position: relative;
  text-align: center;
  font-size: 17px;
  color: #191a1b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  padding: 0 15px;
  background: #fff;
  top: 0;
  height: 44px;
  line-height: 44px;
  z-index: 300;
}


.cinema-schedule .fix-header-title {
  position: fixed;
  width: 100%;
  z-index: 300;
}

.cinema-name {
  position: relative;
  text-align: center;
  font-size: 17px;
  color: #191a1b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  background: #fff;
  height: 44px;
  line-height: 44px;

}

.tags {
  justify-content: center;
  height: 30px;
  line-height: 30px;
}

.tag {
  position: relative;
  text-align: center;
  font-size: 15px;
  white-space: nowrap;
  width: 100%;
}

.info {
  height: 50px;
  line-height: 50px;
  justify-content: center;
  border-top: 1px solid #f4f4f4;
}

.address {
  font-size: 14px;
  height: 50px;
  flex: 1;
  position: relative;
  color: #191a1b;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.telephone {
  text-align: center;
}

.film-info .fix-film-info {

  position: fixed;
  top: 44px;
  z-index: 300;

}
</style>
